<?php
require_once 'duck/DuckInterface.php';
require_once 'adapt/EAdapt.php';
require_once 'duck/DuckGreen.php';
require_once 'duck/DuckRed.php';
require_once 'e/E.php';
require_once 'decker/DuckDecker.php';

class DuckSimulator {
    protected $ducks;

    public function setDuck(DuckInterface $d)
    {
        $this->ducks[] = $d;
    }

    public function quick()
    {
        foreach ($this->ducks as $duck)
        {
            $duck->quick();
        }
    }

    public function getQuickCount()
    {
        $count = 0;
        foreach ($this->ducks as $duck)
        {
            $count += $duck->getQuick();
        }
        return $count;
    }
}


$simulator  = new DuckSimulator();
$simulator->setDuck(new DuckDecker(new DuckRed()));
$simulator->setDuck(new DuckDecker(new DuckGreen()));
$e          = new E();
$simulator->setDuck(new DuckDecker(new EAdapt($e)));
$simulator->quick();
echo "<br>叫的次数: ";
echo $simulator->getQuickCount();